<?php

namespace SisGG\FinalBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Response;
use SisGG\FinalBundle\Entity\Cliente;
use SisGG\FinalBundle\Form\ClienteType;
/**
 * Description of ClienteController
 *
 * @author martin
 */
class ClienteController extends Controller {

    public function indexAction() {
        return new Response('Hello world!');
    }

    public function nuevoClienteAction(){
    $form = $this->createForm(new ClienteType);
    $provincias = $this->getDoctrine()->getEntityManager()->getRepository("SisGGFinalBundle:Provincia")->findAll();
    return $this->render('SisGGFinalBundle:Default:nuevoCliente.html.twig',array('form' => $form->createView(),'provincias'=>$provincias));  
    }
    
    public function procesarClienteAction(){
        $cliente = new Cliente();
        $form = $this->createForm(new ClienteType,$cliente);
        $form->bindRequest($this->getRequest());
        if ($form->isValid()) {
            $em = $this->getDoctrine()->getEntityManager();
            $em->persist($cliente);
            $em->persist($cliente->getDireccion());
            $em->persist($cliente->getTelefonocelular());
            $em->persist($cliente->getTelefonofijo());
            $em->flush();
            return $this->redirect($this->generateUrl('clientes'));
        }
    }
}